using FreeSql.DataAnnotations;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// 用户-角色关联表
/// </summary>
[Table(Name = "user_roles")]
[Index("idx_user_role", "UserId,RoleId", true)] // 联合唯一索引
public class UserRole
{
    /// <summary>
    /// 用户 ID（复合主键之一）
    /// </summary>
    [Column(IsPrimary = true, IsNullable = false)]
    public long UserId { get; set; }

    /// <summary>
    /// 角色 ID（复合主键之一）
    /// </summary>
    [Column(IsPrimary = true, IsNullable = false)]
    public long RoleId { get; set; }

    /// <summary>
    /// 分配时间
    /// </summary>
    [Column(IsNullable = false)]
    public DateTime AssignedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 分配者
    /// </summary>
    [Column(StringLength = 100)]
    public string? AssignedBy { get; set; }

    /// <summary>
    /// 关联的用户
    /// </summary>
    [Navigate(nameof(UserId))]
    public User? User { get; set; }

    /// <summary>
    /// 关联的角色
    /// </summary>
    [Navigate(nameof(RoleId))]
    public Role? Role { get; set; }
}
